class Solution(object):
    def longestConsecutive(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        numSet = set(nums)
        maxLength = 0
        for num in nums:
            if num-1 not in numSet:
                length = 0
                while num in numSet:
                    length+=1
                    maxLength = max(maxLength, length)
                    num+=1
        return maxLength
